package com.tzh.common.utils;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 查询参数
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-03-14 23:15
 */
public class Query<T> extends LinkedHashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	//当前页码
    private int page=1;
    //每页条数
    private int limit=1;

    public Query(){
    }

    public Query(Map<String, Object> params){
        this.putAll(params);

        //分页参数
        if (params.containsKey("page")) {
            this.page = Integer.parseInt(params.get("page").toString());
            this.put("page", page);
        }
        if (params.containsKey("limit")) {
            this.limit = Integer.parseInt(params.get("limit").toString());
            this.put("limit", limit);
        }
        this.put("offset", (page - 1) * limit);


    }


    public Page<T> getPages() {
        return new Page<>(this.page, this.limit);
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }
}
